<? include ("../init.php") ?>
<?php
	$rss = $db->query('SELECT * FROM hs_member WHERE m_enews=1 ORDER BY m_id');
	
	if($rss)
	{
		if($db->numRows()>0)
		{
			$emailfile = 'subscribe.csv';
			$objWrite = fopen($emailfile, "w");
			
				
			if($objWrite)
			{
				fwrite($objWrite, "\"No.\",\"Name\",\"Lastname\",\"email\",\"confirm\" \n");
				$i = 1;
				
				while ($line = $db->fetchNextObject($rss))
				{
					if($line->m_confirm=='1')
					{
						$confirm = 'YES';
					}
					else
					{
						$confirm = 'NO';
					}
					fwrite($objWrite, "\"".($i++)."\",\"".$line->m_name.'","'.$line->m_lastname."\",\"".$line->m_email."\",\"".$confirm."\" \n");
				}
				fclose($objWrite);
				
				echo 'complete';
			}
			else
			{
				echo 'Can\'t open file (subscribe.csv).';
			}
		}
		else
		{
			echo 'Don\'t have subscribe member.';
		}
	}
	else
	{
		echo  'Can\'t query.' ;
	}
	
	
?>